package com.example.demo.domain.category;

import com.example.demo.domain.application.Application;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;

/**
 * 应用在分类中的排序
 *
 * @author yingjianhua
 */
@Entity
@Table(
        uniqueConstraints = @UniqueConstraint(columnNames = {"application_id"}),
        name = "category_application_sort"
)
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class CategoryApplicationSort {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne
    @JoinColumn(name = "application_id", foreignKey = @ForeignKey(name = "none"))
    private Application application;

    @ManyToOne
    @JoinColumn(name = "category_id", foreignKey = @ForeignKey(name = "none"))
    private Category category;

    @Setter
    private Integer sort;

    public CategoryApplicationSort(Application application, Category category, Integer sort) {
        this.application = application;
        this.category = category;
        this.sort = sort;
    }

    @Override
    public String toString() {
        return "CategoryApplicationSort{" +
                "id=" + id +
                ", application=Application{id=" + application.getId() + "}" +
                ", category=Category{id=" + category.getId() + "}" +
                ", sort=" + sort +
                '}';
    }
}
